package fr.afcepf.ai85.gepeto.managedBean;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import fr.afcepf.ai85.businessObj.ResultatPointage;
import fr.afcepf.ai85.businessObj.ResultatPointageConsultation;
import fr.afcepf.ai85.gepeto.service.ServicePointage;

@ManagedBean (name="beanPoint")
@SessionScoped
public class BeanPointage {

	// List<ResultatPointage> listPoint = ServicePointage.ListePointage( 3,
		// 2,"2013-04-04");

	
///////////////////////////////////////////////////// liste Pointage /////////////////////////////////////////////////////////////////////////////
		List<ResultatPointage> listPoint = new ArrayList<ResultatPointage>();

 ///////////////////////////////////////////////////// liste Consultation /////////////////////////////////////////////////////////////////////////////

		List<ResultatPointageConsultation> listPointConsult ;

////////////////////////////////////////////////////////////Getters / setters	/////////////////////////////////////////////////////////////////
		public List<ResultatPointageConsultation> getListPointConsult() {
			return listPointConsult;
		}

		public void setListPointConsult(
				List<ResultatPointageConsultation> listPointConsult) {
			this.listPointConsult = listPointConsult;
		}

		public List<ResultatPointage> getListPoint() {
			return listPoint;
		}

		public void setListPoint(List<ResultatPointage> listPoint) {
			this.listPoint = listPoint;
		}

////////////////////////////////////////////////////////////declaration paramettres	/////////////////////////////////////////////////////////////////
		

		private String idEcole;
		private String idActivite;
		private String dateInscr;
		
		private String consIdEcole;
		private String consIdActivite;
		private String consDateInscr;

////////////////////////////////////////////////////////////pointage 	/////////////////////////////////////////////////////////////////

		public String effectuerPointage() throws ParseException
		{
			System.out.println("~~~ BeanPointage : effectuerPointage()");
			
			for( ResultatPointage rp : listPoint  )
			{
				System.out.println(rp.toString());

				
				if(rp.absent)
				{
					SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
					Date d = sdf.parse(dateInscr);
					
					int absjustif = 0;
					if(rp.absenceJustif) { absjustif = 1; }
					
					System.out.println("Enfant absent" + rp.getNomEnf() + "\t" + rp.isAbsent() );
					ServicePointage.InsertAbsence(rp.idInscription, idActivite,
															d, rp.idEleve, rp.motifAbsence, absjustif);
					
				}

			}
					
//			ServicePointage.InsertAbsence(idActivite, d);
			
//			ServicePointage.InsertAbsence();
//			for (int i = 0; i < getDataTable().getRowCount(); i++) {
//			    getDataTable().setRowIndex(i);
//			    Object object = getDataTable().getRowData();
//			}
			
			return "";
		}
		
		
		public String chargementTablePointage() {
			int idIEcole = Integer.parseInt(idEcole);
			System.out.println("iIdPeriode = " + idEcole);

			int idIActivite = Integer.parseInt(idActivite);
			System.out.println("iIdEcole = " + idActivite);

			System.out.println(dateInscr);
			
			listPoint = ServicePointage.ListePointage(idIEcole, idIActivite,dateInscr);
			System.out.println("Bean pointage : chargementTablePointage()");

			return "";
		}

		public   String chargementTablePointageConsult() {
			int ConsIntEcole = Integer.parseInt(consIdEcole);
			System.out.println("iIdPeriode = " + idEcole);

			int ConsIntActivite = Integer.parseInt(consIdActivite);
			System.out.println("iIdEcole = " + idActivite);

			System.out.println(dateInscr);
			listPointConsult = ServicePointage.PointageConsultation(ConsIntEcole, ConsIntActivite, consDateInscr);
			
			System.out.println("Bean pointage : chargementTablePointageConsult()");

			return "";
		}	
		
		public static void main(String[] args) {
			System.out.println("main de beanFacturation");
			
//			chargementTablePointageConsult();
//			
//			for(ResultatPointageConsultation rf : listPointConsult)
//			{
//				System.out.println(rf.getNomEnf() + " " + rf.getPrenomEnf());;
//			}
			
//			ServicePointage sp=new ServicePointage();
//			List<ResultatPointageConsultation> liste=sp.PointageConsultation(1,1, "03/25/2013");
			
			
		}
	
	
		
		// GETTERS & SETTERS
		
		public String getConsIdEcole() {
			return consIdEcole;
		}

		public void setConsIdEcole(String consIdEcole) {
			this.consIdEcole = consIdEcole;
		}

		public String getConsIdActivite() {
			return consIdActivite;
		}

		public void setConsIdActivite(String consIdActivite) {
			this.consIdActivite = consIdActivite;
		}

		public String getConsDateInscr() {
			return consDateInscr;
		}

		public void setConsDateInscr(String consDateInscr) {
			this.consDateInscr = consDateInscr;
		}

		public String getIdEcole() {
			return idEcole;
		}

		public void setIdEcole(String idEcole) {
			this.idEcole = idEcole;
		}

		public String getIdActivite() {
			return idActivite;
		}

		public void setIdActivite(String idActivite) {
			this.idActivite = idActivite;
		}

		public String getDateInscr() {
			return dateInscr;
		}

		public void setDateInscr(String dateInscr) {
			this.dateInscr = dateInscr;
		}
		
}


